package com.oasistudio.ads.expert.banner;

import android.app.Activity;
import android.widget.LinearLayout;

import com.oasistudio.ads.expert.R;
import com.vpon.adon.android.AdListener;

public class AdViewVpon {
	VponAdRequestListener adRequestListener;
	Activity activity;
	public static final String UNION = "vpon.com";
	public AdViewVpon(Activity activity){
		this.activity = activity;
		this.adRequestListener = new VponAdRequestListener(activity, UNION);
		
		addVponAd();
	}
	
	/************************** adon.vpon.com start *************************/
	private void addVponAd() {
		LinearLayout adContainer = (LinearLayout) activity.findViewById(R.id.ads_container);
		adContainer.addView(new TitleBuilder().createTitle(activity, UNION));

		LinearLayout adonContainer = new LinearLayout(activity);
		adContainer.addView(adonContainer);

		com.vpon.adon.android.AdView adView = new com.vpon.adon.android.AdView(activity); // 1
		adView.setAdListener(this.adRequestListener);
		adonContainer.addView(adView); // 2
		boolean autoRefreshAd = true; // 3
		adView.setLicenseKey("ff8080813409002b013421c554db0397", com.vpon.adon.android.AdOnPlatform.CN, autoRefreshAd); // 3
		adView.setAdListener(this.adRequestListener); // 5
		System.out.println("AdOn SDK Version " + adView.getVersion());
	}

	/************************** adon.vpon.com end *************************/

	class VponAdRequestListener extends AbstractAdsExpertAdListener implements AdListener{
		
		public VponAdRequestListener(Activity activity, String union){
			super(activity, union);
		}

		@Override
		public void onFailedToRecevieAd(com.vpon.adon.android.AdView arg0) {
			// TODO Auto-generated method stub
			this.fail();
		}

		@Override
		public void onRecevieAd(com.vpon.adon.android.AdView adView) {
			// TODO Auto-generated method stub
			this.succeed();
			AdHistory.saveAd(UNION, adView);
		}
	}
}
